Repository navigation
refactor(frontend): give failureText the text of each failed request, and lint the text outside it - #543
Conversation
…f each failed request The toast, QueryError, useServerErrors, the stale alert, and the forms and pages of membership, invites, and weather now show failureText(error). It maps each kind of failure to one text in an exhaustive Record, and the Server text of a 4xx refusal passes through. The error of a query or a mutation has the type unknown, so a component cannot show its message. Delete the old paths: the text constants and displayMessage, title, and detail of ProblemDetailsError, handleErrorResponse of api-client.ts, and the local fallback texts of the forms. The text that the user sees changes only where it was wrong: - a 401 with a problem body shows the sign-in text, not the token detail - an error of the app shows "The app has a fault. Reload the page, then try again." in place of its developer message, an empty text, or "The save failed. Try again." - the home page says "Your user did not load. Reload the page." in place of "The Server could not load your user."
messages/failure-text reads types and fails outside src/lib/request-failure.ts on the message of an Error, the detail or the title of a problem, a new Error that the code does not throw, and a root error of a form with a text of its own. Each error names failureText of @/lib/request-failure.
Proof: the checks fail on past mistakesEach section restores files with
|
|
review-gate: passed 2879decd Two rounds of Round 2 lows fixed after that review, in 6268971: a field name that starts with "root", the Open, low:
|
… as in the other failure texts
|
PASS+NOTES Independent verify of PR head 2180ddf merged into base Real app: each failure kind, base vs landRecipe
All 16 ARIA snapshots of Screenshots (land): Developer checks (scratch code, removed)
CI bar (land worktree, local)
Notes (none block)
|
…rue (#546) ## Why The `api-contract` and `without-examples` jobs fail on `main` since #543. Six `messages/failure-text` cases in `frontend/eslint.config.test.js` get no report in CI, and pass locally. ## What changed `failureTextMessages` in the test sets `disallowAutomaticSingleRunInference: true` on its own `ESLint`. With `CI=true`, typescript-eslint infers a single run. In that mode it counts the parses of each path, and takes each parse after the first for a `--fix` pass, so it gives the file an isolated program with no imports and no default lib. Every test lints the same path, `src/components/query-error.tsx`, so each test after the first got no types, and `isError` and `isProblemText` found nothing. The first case, which needs no types, passed. ## Blast Radius Test only. `eslint.config.js` is unchanged, and `pnpm lint` in CI parses each file once, so the rule keeps its types there. ## Verification - Reproduced the six failures locally with `CI=true pnpm vitest run eslint.config.test.js`. - After the change: 92 of 92 pass with `CI=true` and without it, and `CI=true pnpm test` passes 910 of 910. `pnpm lint` is clean. Co-authored-by: Amp <amp@ampcode.com>
Why
Agents keep writing SPA error text that names a cause the SPA does not know. The past cases are #474, #485, and PR #500, which said "Check your connection" when the Server was down. Each fix patched one screen, so the next screen got it wrong again.
What changed
failureText(error)infrontend/src/lib/request-failure.tsis the one owner of the text of a failed request, query, or mutation. An exhaustiveRecord<SpaTextKind, string>holds the texts of the SPA, and the Server text of a 4xx refusal passes through.Register.defaultErrorisunknown, soquery.error.messagedoes not build.apiClienttoast,QueryError,useServerErrors,StaleVersionAlert(loadFailure: stringbecameloadError: unknown),StartTenantForm,useMembership, the join page andjoinViewOf, the workshop edit form, and the weather page.serverFaultMessage,noAnswerMessage,timedOutMessage,displayMessage,title, anddetailofProblemDetailsError,handleErrorResponse, and the local fallback texts.messages/failure-text(typed) fails outside the owner on themessageof anError(also destructured, or after a shape check or a cast), thedetailortitleof a problem, anew Errorthat the code does not throw or reject, and a root form error with its own text. Each error namesfailureText.Texts that change, each one wrong before:
Scope
The level is architecture plus a type plus a lint. The owner and the type alone do not block
error.messageafter aninstanceofnarrowing, a hand-madenew Error('...')(#500), or a literal text on a root form error. Only the lint sees those. Out of scope: the list pages still show a toast and a QueryError with the same text (#485 class), and the chunk-load texts ofpage-error.tsxandcontrol-load-error.tsx.Tradeoffs
One
refusedkind, not one SPA text per 4xx status. The Server writes the refusal text, and the FSTMSG checks already own it.Blast Radius
On the next template merge, an app that reads
displayMessage,title,detail, the text constants,loadFailure, orquery.error.messagefails its build. One change is silent:ProblemDetailsError.messageis now developer text, and only this lint catches code that shows it. Typed parsing ofsrc/**makespnpm lintabout 60% slower (10 s to 17 s, warm).Verification
pnpm lint,pnpm build,pnpm test(907 passed), andpnpm test:e2e(370 passed) are green locally. The checks fail on the pre-fix code of ccc196e (#437), c961b2e (#336), 2e37e45^ (before #500), and 3b7a3c7 (main): 27 lint errors and 4 type errors. The output is in the first comment.